package com.wdh.kjs.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;
import com.wdh.kjs.activity.NoticeDetailsActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by feifei on 2016/4/27.
 */
public class NoticeAdapter extends BaseAdapter {
    private List<HashMap<String, String>> data=new ArrayList<HashMap<String,String>>();
    private Context context;
    private HashMap<String, String> maps=new HashMap<String, String>();
    public NoticeAdapter(Context context, List<HashMap<String, String>> data) {
        this.data=data;
        this.context = context;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.noticeadapter, null);
            viewHolder.notice_inmage = (ImageView) convertView.findViewById(R.id.notice_inmage);
            viewHolder.notice_text = (TextView) convertView.findViewById(R.id.notice_text);
            viewHolder.notice_text1 = (TextView) convertView.findViewById(R.id.notice_text1);
            viewHolder.noticeadapte_linear = (LinearLayout) convertView.findViewById(R.id.noticeadapte_linear);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        maps  = data.get(position);
        ItemClick itemClick = new ItemClick(position);
        viewHolder.noticeadapte_linear.setOnClickListener(itemClick);
//        viewHolder.notice_inmage.setImageResource(R.mipmap.arrow_right);
        viewHolder.notice_text.setText(maps.get("title"));
        viewHolder.notice_text1.setText(maps.get("time"));

        return convertView;
    }



    class ViewHolder{
        TextView notice_text;
        TextView notice_text1;
        ImageView notice_inmage;
        LinearLayout noticeadapte_linear;
    }


    private class ItemClick implements View.OnClickListener{
        private int Myposition;
        public ItemClick(int position) {
            Myposition = position;
        }

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, NoticeDetailsActivity.class);
            intent.putExtra("userReceiveMessageId", data.get(Myposition).get("userReceiveMessageId"));
//            intent.putExtra("time2",maps.get("time"));
//            intent.setClass(this, NoticeDetailsActivity.class);
            context.startActivity(intent);
        }
    }
}
